package org.agile.grenoble;

import java.sql.SQLException;
import java.util.Locale;

import org.agile.grenoble.client.AnswersStorageClient;
import org.agile.grenoble.client.GetOrCreateUserClient;
import org.agile.grenoble.client.GetQuestionsClient;
import org.agile.grenoble.configuration.Messages;
import org.agile.grenoble.gui.NokiaControler;
import org.agile.grenoble.gui.NokiaSwing;
import org.agile.grenoble.questions.QuestionsDocument;
import org.agile.grenoble.user.User;

/**
 * 
 * 
 * 
 * @author build
 *
 */
public class NokiaTest {

	 
	private static NokiaSwing initMainGUI() {
		NokiaSwing myDisplay = new NokiaSwing();
		myDisplay.setVisible(true);
		return myDisplay;
	}	
	
	/**
	 * 
	 * @param argv
	 */
	public static void main (String[] argv) {
		System.out.println(Locale.getDefault()); 
		Locale.setDefault(Locale.FRENCH);
		System.out.println("setting local to : FR");
		System.out.println(Locale.getDefault()); 
		
		
		System.out.println(Messages.getString("NokiaTest.label")); //$NON-NLS-1$
		//parse arguments
		QuestionsDocument questions=null;
		AnswersStorageClient iAnswersStorage = new AnswersStorageClient(); 
		GetOrCreateUserClient iUserStorage = new GetOrCreateUserClient();  
		//IAnswersStorage storage =	new AnswersStorage();
		try {
			
			questions = GetQuestionsClient.GetQuestionsClient();
			
			//String filename = Configuration.getString("NokiaTest.questionsPath") ; //$NON-NLS-1$
			//QuestionsReader.printItems(filename);
			//questions = QuestionsReader.getQuestions(filename);
			
			
			//call master class
			NokiaSwing gui = initMainGUI();
			gui.generateQuestionDisplay(questions.getQuestions());
			NokiaControler nc = new NokiaControler();
			nc.setNokiaSwing(gui);
			nc.setQuestions(questions);
			
			
			iAnswersStorage.initializeDB(questions.getQuestions());
			
			
			nc.setUserStorage(iUserStorage);
			nc.setAnswersStorage(iAnswersStorage);
			nc.startHomePage(); //blocker call
			User user = nc.startUserRegistration(); // blocker call
			nc.startQuestions(user);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		System.out.println(Messages.getString("NokiaTest.EndLabel")); //$NON-NLS-1$
	}

	
	
		
	
}
